package com.beyond.pm.component

import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.wrapContentHeight
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Snackbar
import androidx.compose.material3.SnackbarHost
import androidx.compose.material3.SnackbarHostState
import androidx.compose.material3.Text
import androidx.compose.material3.TextButton
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.unit.dp
import com.beyond.pm.R

/**
 * @author chen
 * @time 2023/6/6 14:25
 * @name ProjectManage
 * @class describe
 */
@Composable
fun MySnackBar(
 snackBarHostState: SnackbarHostState,
 modifier: Modifier = Modifier,
 onDismiss: () -> Unit = { }
) {
 SnackbarHost(
  hostState = snackBarHostState,
  snackbar = { data ->
   Snackbar(
    modifier = Modifier.padding(16.dp),
    content = {
     Text(
      text = data.visuals.message,
      style = MaterialTheme.typography.bodyMedium,
     )
    },
    action = {
     data.visuals.actionLabel?.let {
      TextButton(onClick = onDismiss) {
       Text(
        text = stringResource(id = R.string.dismiss),
        color = MaterialTheme.colorScheme.inversePrimary
       )
      }
     }
    },
    actionOnNewLine = true
   )
  },
  modifier = modifier
   .fillMaxWidth()
   .wrapContentHeight(Alignment.Bottom)
 )
}